package 测试案例;
import java.util.*;

public class Test12 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long M = sc.nextLong();
        long N = sc.nextLong();
        long[] arr = new long[33];
        char[] ch = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'A', 'B', 'C', 'D', 'E', 'F'};
        int conut = 0;//多少个进制数
        boolean is = false;
        if (M < 0) {
            M = -M;
            is = true;
        }

        while(M >= N){
            M -= N;
            conut ++;
        }
        arr[0] = M ;
        arr[1] = conut;

        int t = 1;
        while(arr[t] != 0){
            while(arr[t] >= N){
                arr[t] -= N;
                arr[t + 1] += 1;
            }
            t++;
        }

        if (is) {
            System.out.print("-");
        }

        for (int i = t - 1; i >= 0; i--) {
            System.out.print(ch[(int)arr[i]]);
        }
    }
}


